<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of bonus_report
 * class untuk laporan bonus
 *  - board
 *  - board cycle
 * 
 * @author tejomurti
 */
class bonus_report extends Bonus_helper{
    //put your code here
    
    private $network_id;
    
    public function __construct($id) {
        $this->network_id=$id;
        
    }
    
    /**
     * mendapatkan bonus board jaringan
     */
    public function board_network()
    {
       
        $board_network = vo_network::get_board_network($this->network_id, '0');
         $akumulasi_sponsor = vo_network::get_accumulative_sponsor_board($this->network_id, '1');
         $data=array();
         if ($board_network) {
            $no = 1;
            foreach ($board_network as $id => $row_network) {
                $board_manager = vo_network::get_board_active(1, $row_network['board_network_id']);
                $sponsor_count = vo_network::get_board_sponsor_count($row_network['board_network_id']);
                $roll_count = vo_network::get_board_roll_count($row_network['board_network_id']);

                $arr_start=0;
                if ($board_manager) {
                    foreach ($board_manager as $row_manager) {
                        $arr_board_group = explode(" | ", trim($row_manager['board_network_group']));
                        $network_group_order = array_search($row_network['board_network_id'], $arr_board_group);
                        $network_group_order++;
                        $level = function_lib::get_level($network_group_order);
                        $top_mid = vo_network::get_board_network_mid($row_manager['board_leader_board_network_id']);

                        $data['jaringan_manager_board'][$arr_start]['id_board']=$row_manager['board_id'];
                        $data['jaringan_manager_board'][$arr_start]['id_member']=$row_network['board_network_network_mid'];
                        $data['jaringan_manager_board'][$arr_start]['posisi_level']=$level;
                        $data['jaringan_manager_board'][$arr_start]['jml_sponsor']=$sponsor_count;
                        $data['jaringan_manager_board'][$arr_start]['jml_cycle']=$roll_count;
                        
                        $arr_start++;
                        $no++;
                    }
                }
            }
        }
        
        if ($board_network) {
            $no = 1;
            foreach ($board_network as $id => $row_network) {
                $board_director = vo_network::get_board_active(2, $row_network['board_network_id']);
                $sponsor_count = vo_network::get_board_sponsor_count($row_network['board_network_id']);
                $roll_count = vo_network::get_board_roll_count($row_network['board_network_id']);

                $arr_start=0;
                if ($board_director) {
                    foreach ($board_director as $row_director) {
                        $arr_board_group = explode(" | ", $row_director['board_network_group']);
                        $network_group_order = array_search($row_network['board_network_id'], $arr_board_group);
                        $network_group_order++;
                        $level = function_lib::get_level($network_group_order);
                        $top_mid = vo_network::get_board_network_mid($row_director['board_leader_board_network_id']);

                        $data['jaringan_director_board'][$arr_start]['id_board']=$row_director['board_id'];
                        $data['jaringan_director_board'][$arr_start]['id_member']=$row_network['board_network_network_mid'];
                        $data['jaringan_director_board'][$arr_start]['posisi_level']=$level;
                        $data['jaringan_director_board'][$arr_start]['jml_sponsor']=$sponsor_count;
                        $data['jaringan_director_board'][$arr_start]['jml_cycle']=$roll_count;
                        
                        $arr_start++;
                        $no++;
                    }
                }
            }
        }
        
         return array(
             'jaringan_manager_board'=>$data['jaringan_manager_board'],
             'jaringan_director_board'=>$data['jaringan_director_board'],
             'akumulasi_sponsor'=>$akumulasi_sponsor,
         );
    }
    
    /**
     * mendapatkan data board cycle
     * @return array 
     */
    public function board_cycle()
    {
         $board_network = vo_network::get_board_network($this->network_id, '1');
         $data=array();
         if ($board_network) {
            $no = 1;
            foreach ($board_network as $id => $row_network) {
                $board_manager = vo_network::get_board_roll(1, $row_network['board_network_id']);

                $arr_start=0;
                if ($board_manager) {
                    foreach ($board_manager as $row_manager) {
                        $status = 'ROLL';
                        $top_mid = vo_network::get_board_network_mid($row_manager['board_leader_board_network_id']);

                        $data['manager_board'][$arr_start]['id_class']=$row_manager['board_id'];
                        $data['manager_board'][$arr_start]['id_member']=$row_network['board_network_network_mid'];
                        $data['manager_board'][$arr_start]['status']=$status;
                        $data['manager_board'][$arr_start]['tgl_roll']=function_lib::convert_datetime($row_manager['board_end_datetime'], 'text', '', ':', 'ina');
                     
                        $no++;
                        $arr_start++;
                    }
                } 
            }
        } 
        
          if ($board_network) {
            $no = 1;
            foreach ($board_network as $id => $row_network) {
                $board_director = vo_network::get_board_roll(2, $row_network['board_network_id']);

                $arr_start=0;
                if ($board_director) {
                    foreach ($board_director as $row_director) {
                        $status = 'ROLL';
                        $top_mid = vo_network::get_board_network_mid($row_director['board_leader_board_network_id']);

                        
                        $data['director_board'][$arr_start]['id_class']=$row_director['board_id'];
                        $data['director_board'][$arr_start]['id_member']=$row_network['board_network_network_mid'];
                        $data['director_board'][$arr_start]['status']=$status;
                        $data['director_board'][$arr_start]['tgl_roll']=function_lib::convert_datetime($row_director['board_roll_datetime'], 'text', '', ':', 'ina');
                     
                        $arr_start++;
                        $no++;
                    }
                }
            }
        }
        
        return array(
            'manager_board'=>$data['manager_board'],
            'director_board'=>$data['director_board'],
        );
    }
}

?>
